package com.projectplace.api;

/*
 * Copyright (c) 2011 Projectplace International AB
 * Permission is hereby granted, free of charge, to any person 
 * obtaining a copy of this software and associated documentation 
 * files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, 
 * publish, distribute, sublicense, and/or sell copies of the Software, 
 * and to permit persons to whom the Software is furnished to do so, 
 * subject to the following conditions:The above copyright notice and this 
 * permission notice shall be included in all copies or substantial portions of the Software.
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import org.apache.http.HttpResponse;

import android.os.Handler;

import com.projectplace.api.Callback.Callback;
import com.projectplace.api.CallbackWrapper.CallbackWrapper;

/**
 * To be able to get a projects containers(folders) and documents you first most get the project container id with the function ProjectApi.getProjectTools()
 * after that you can use DocumentContainerContents to get both folders and documents. 
 * @author johanma
 *
 */

public class DocumentsApi implements Api {

	//So you can't initiate this class, makes it singelton
	private DocumentsApi(){ super(); }
	
	public static void getDocumentComments(PPClient client, final Handler handler,String documentID,final Callback.ResponceListenerDocumentComments response){
		String fetchUri = PROJECTPLACE_DOCUMENT_COMMENTS+documentID+"/comments.json";
		PPClient.sendRequest(fetchUri, new getInfoHandler(){
			public void onFinish(HttpResponse user, Error err){
				CallbackWrapper.GetDocumentComments tempWrap = new CallbackWrapper.GetDocumentComments(response);
				tempWrap.setResponse(user,err);
				handler.post(tempWrap);
			}
		});
	}
	
	public static void getDocumentContainerContents(PPClient client, final Handler handler,String documentContainerId,final Callback.ResponceListenerDocumentContainerContents response){
		String fetchUri =  PROJECTPLACE_DOCUMENT_CONTAINERCONTENTS + documentContainerId+"/contents.json";;
		PPClient.sendRequest(fetchUri, new getInfoHandler(){
			public void onFinish(HttpResponse user, Error err){
				CallbackWrapper.GetDocumentContainerContents tempWrap = new CallbackWrapper.GetDocumentContainerContents(response);
				tempWrap.setResponse(user,err);
				handler.post(tempWrap);
				
			}
		});
	}
	
	/**
	 * This method is not used! Instead a local asynctask method is used inside DocumentView
	 */
	//TODO::
	public static void DocumentDownload(PPClient client, final Handler handler,String documentID,String version, final Callback.ResponceListenerDocumentContainerContents response){
		

	}
	//TODO::
	public static void getDocumentProperties(PPClient client, final Handler handler,String documentID){
		
	}
	//TODO::
	public static void getDocumentVersions(PPClient client, final Handler handler,String documentID){
		
	}
	//TODO::
	public static void DocumentTouch(PPClient client, final Handler handler,String documentID){
		
	}
	
	
	public static void getUserRecentDocuments(PPClient client, final Handler handler,final Callback.ResponseListenerUserRecentDocuments response){
		String fetchUri =  PROJECTPLACE_DOCUMENTS_USERRECENT;
		PPClient.sendRequest(fetchUri, new getInfoHandler(){
			public void onFinish(HttpResponse user, Error err){
				CallbackWrapper.GetDocumentRecent tempWrap = new CallbackWrapper.GetDocumentRecent(response);
				tempWrap.setResponse(user,err);
				handler.post(tempWrap);
			}
		});
	}
	
	//TODO::
	public static void DocumentUpload(){
	
	}
	
	public static void postDocumentComments(PPClient client,String documentID,String text, final Handler handler,final Callback.ResponceListenerPostDocumentComment response){
		String fetchUri = PROJECTPLACE_DOCUMENT_COMMENTS+documentID+"/comments.json";
		PPClient.postRequest(fetchUri,text, new getInfoHandler(){
			public void onFinish(HttpResponse user, Error err){
				CallbackWrapper.PostDocumentComment tempWrap = new CallbackWrapper.PostDocumentComment(response);
				tempWrap.setResponse(user,err);
				handler.post(tempWrap);
			}
		});
	}
}
